home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-11 | 6.6 KB | 162 lines | [TEXT/R*ch] |
- appe Windows
-
- If you have seen the new Speech Manager, then you know that a background
- only application can put a window onto the screen (contrary to popular
- belief). The new Text Services Manager in System 7.1 offers documented
- hooks for creating, disposing, and handling floating windows. These
- windows are layer independent (they are floating above all programs
- and windows), and can work without patching traps (well, a quick jGNEFilter,
- but no traps).
-
- This program demonstrates a shell application that puts a TSM window
- onto the screen, and intercepts update, click, and key events. Filling
- in the handler functions is the easiest way to put up your own floater.
- Wrapper functions restore global context, current resource file, GrafPort,
- and heap zone, to make standard handling routines much easier to write.
-
- The program now works as a foreground or background application. The
- software is distributed as a foreground app, but the process to convert
- a program to background app is to set the "Background Only" flag in
- the 'SIZE' resource (or Project Flags) and to make a system extension,
- you should change the file type from 'APPL' to 'appe'. I have added
- a drag-n-drop utility to convert between foreground and background apps,
- as well as a file describing the differences.
-
- I like the close box on floater windows, because its an easy way to
- quit the program without relying on a quit Apple Event. I have added
- support for hiding windows with Cmd-Escape, and to respond to screen
- savers and programs that take over the screen (hide the menu bar).
-
-
- Legal Stuff
-
- Its yours if you like it. This shell is free for you to modify and
- expand upon. I would like it if you tell me if you use this, but you
- are under no obligation. Likewise, this library is provided as is --
- I fixed up all the bugs I could find/create, so I could use it myself --
- but that doesnt necessarily mean its fit for wiping the toilet seat. :)
-
- The enclosed extension "TSM Fix" is intended to fix problems with the
- jGNEFilter missing clicks bug. This INIT is also free, to be distributed
- with (or without) any software you have written.
-
- In addition, the enclosed utility "appe <-> APPL" is useful so that you
- only have to distribute a single binary. Again, the program is free
- to be redistributed at your whim.
-
-
- Using the library
-
- In scanning the source for the program, there are several key areas
- that you should recognize. These gotchas are important things to
- remember when modifying or adding to the source.
-
- main.c
-
- Facelss background applications seem to require additional
- stack space. I found that 16k of additional stack seems to
- work. BTW, keep the memory footprint down (cuz people dont like
- memory hogs) but not too small or you will have heap space
- problems. I had to fine tune my demo apps to work well in
- limited memory space.
-
- In a background-only application, the only Toolbox initialization
- call that you should make is InitGraf() to setup the QD globals.
- InitWindows() plays with the layer manager in a bad way, and
- should be avoided.
-
- I use Gestalt() to check my environment, and exit gracefully
- with a Notification Mgr dialog.
-
- windows.c
-
- The current TSM does not create a Color Window for us, so there
- is a #define in "main.h" that gives you the option to patch
- traps. Although this violates our promise of Patch-Free operation,
- it gives us color -- so lose or leave it at your whim.
-
- Hooks are set up for you to implement the following window
- functions: Update, Click, Keydowns, Zoom, Reveal (on show
- and hide), and Idle time.
-
- Key events can be intercepted or passed through at your
- discretion. By default, only Cmd-Escape is applicable and
- it is passed through so that other floaters can see it.
- (This would be a useful feature for all similar apps to
- implement, please?)
-
- Controls like scroll bars or other window-activation
- sensitive elements should always be active in floaters,
- since all floaters are considered active regardless of
- position in window list.
-
- event filter.c
-
- The jGNEFilter is the best way to intercept the events
- directed at our window. We check mouse and key events
- for relevance, and then convert them to null events
- if directed at our window.
-
- Note: the jGNEFilter may miss occasional mouse-downs.
- Its a bug in the OS, and you need to look at my "TSM Fix"
- for a patch that rememdies the problem.
-
- Our floaters dont get update events either, so we manually
- check the update region of our window and call the update
- routine. We have to check every event because update events
- aren't necessarily posted when just our window needs
- drawing.
-
- (v1.51) Updated the InScreenSaver() function to check the
- menubar height ONLY in when in the foreground, or to
- check the cached height in the background.
-
- contexts.c
-
- Contexts are the mechanism we use for setting up and cleaning
- up relevant variables and registers. A context struct
- defines some major elements that I need. Be sure that code
- you add is not dependent on other lo-mem globals without the
- right save and restore context wrappers. Also, since a
- context plays with A5 and your app globals, you have to
- be careful about globally stored contexts.
-
- To get information about the front application, you may need
- to restore its context (to get heap info or access private
- globals off A5). Be sure to carefully manage when you are
- using your apps context and someone elses.
-
- In the first version the resource file was saved and restored
- by its (open) refNum, which turns out to be wrong -- the resource
- chain is *not* universal (thanks Peter Lewis). The current
- solution is to create a duplicate resource file (clone the app's
- resources), and open/close it each event filter.
-
- (v1.51) Set the location of the temporary file to the
- temporary items folder now. DOH! If unable, then it
- tries the System Folder, then the app's current folder.
-
- Other notes
-
- In "main.h" I define a Hot Application, which lets you tie
- your floater to an particular application creator type. If
- you change this value, your floaters will only be visible
- when that application is the front program. This is a great
- way to give specialized information about a particular
- program without modifying it.
-
- Perhaps it would be better to handle events within my own
- event loop, but since there is no easy way to PostEvent()
- from one apps context to another this is not done. If you
- have a suggestion to help me, I would like to make this
- change.
-
-
- Finally, I want this to be a stable mechanism for something that you
- shouldn't be able to do. Despite the interface guidelines, there may
- be a use for doing this. Please send me bug reports and suggestions
- for improving this tool.
-
- Matt Slot
- fprefect@umich.edu
-